Beginners Programming
Demos
Everyone has that one special reason for downloading Liberty BASIC. For me, it was a simulated blood pressure program. In September, 2003, I had previewed a CD-ROM offered by one of the major publishers of nursing education textbooks. The description sounded promising: a tutorial teaching the mechanics of obtaining a blood pressure complete with simulated blood pressure readings. The student could practice reading the aneroid manometer (round dial with a needle gauge) during the tutorial pretest and posttest. Sure enough, the program offered a pretest blood pressure display. The reading was a perfect 120/70.
The blood pressure is comprised of two readings. The first, higher number (systolic) is the greatest amount of pressure exerted by the heart. This systolic pressure is obtained when the heart is contracting to force blood out to the body. The second, lower number (diastolic) is the least amount of pressure exerted by the heart. The diastolic pressure is obtained when the heart is at rest between heartbeats. Up until recently, any reading greater than 140 systolic and / or 90 diastolic has been considered above normal, meaning high blood pressure or hypertension. More recently, the American Heart Association has determined that any systolic reading greater than 120 and / or a diastolic reading greater than 80 is considered hypertensive and should be treated. Monitoring the blood pressure readings is a fundamental task of nursing.
The simulated blood pressure of 120/70 was aesthetically pleasing and certainly realistic. The price of the program was perhaps a bit steep (in excess of $300), but some beginning students require more practice than others in correctly reading the gauge. I was optimistic as I worked my way through the tutorial. Imagine my disappointment when the tutorial showed the exact same display of the 120/70 blood pressure reading. I finished the tutorial and began the posttest. The blood pressure reading? You guessed it - 120/70! That was when I thought, if a person could program 120/70, how hard would it be to program random readings? It turned out the math wasn't hard at all. Creating that aesthetically pleasing display, though, did turn out to be quite a challenge.
The first problem was drawing the dial gauge face and needle. The typical aneroid manometer is measured in even increments from 0 to 300, with an additional 20 units unused. This gives 320 increments within a circle having 360 degrees. Each increment is 360/320 (or 9/8) degrees. I spent a considerable amount of time figuring out x and y coordinates to visually line up the number markings of the gauge. (Later, I would discover the stringwidth? command and let the computer determine where to draw those numbers.) Finally I had a routine that would draw a satisfactory gauge face. Next, I would need a sweeping gauge needle.

151 sprites: 0, 2, 4, 6, 8, 10, 12 . . . 294, 296, 298, 300. But, the program worked. Once inflated, the needle gauge began descending, fluctuating and making a 'beat' sound at the systolic reading, continuing to fluctuate and beat until the diastolic reading was reached, then descending to zero without fluctuation - just like the REAL thing.
A few queries to the LB community on the conforums and I was well on my way to creating listboxes for user input and buttons for event controls. And there were almost as many buttons as sprites. There was a button to start the program, a button to end the program, a button to inflate, a button to deflate, a button to repeat the same blood pressure, a button to obtain a new random reading, a button to evaluate the user's reading, a button to give directions about the buttons… There were regular buttons and there were .bmp buttons.

Gordon Sweet, having read one of my queries, asked to view the program. With Gordon's detailed instructions, I was able to 'zip' my first program and send it to England, complete with 151 sprites and 14 buttons. Gordon suggested I abandon the sprites and learn how to use the flush, discard, draw, redraw, delsegment, etc. commands. Those commands didn't accomplish exactly what I desired, but I did stumble across the fact that a "drawsprites" command erases all unflushed drawing. Hence, this program is a hybrid of turtle graphics and sprite commands. The dial face is set in the background as for sprites, but the needle placements are drawn and then stored in memory as segments. It is the segments that are then redrawn to achieve the descending, fluctuating effect of a blood pressure. The 151 sprites were quickly trucked off to the recycle bin. Of course, there were still those 14 buttons - actually 16 now because Gordon suggested that Help and About items needed to be included.
About this time (mid - December), Alyce Watson posted a snippet in answer to a user's question regarding menu options. A menu? Would a menu be better than 16 buttons? You bet! Some buttons needed to remain, but once the menu was in place, quite a few of those buttons joined company with those 151 sprites in the recycle bin. Since then one more menu has been added.
Using a Notice for help and command is certainly efficient, but not terribly visually attractive. Tom Nally was kind enough to offer me some tips about Help windows. With Tom's help (both directly and in studying Tom's help windows, see LBSH, Newsletter #103 and Symmetrical Paint, Newsletter #118), I learned how to screen capture and 'shrink' the image. I also learned, through trial and error, that using a dialog_modal window for a help screen keeps that help screen on top, but the placement of the dialog_modal window is not easily controlled. The dialog_modal window doesn't respond to the usual upperLeftX and upperLeftY commands.
The original program contained two lofty bits of code in determining the random systolic and diastolic readings. Since the systolic value could be any even number from 70 to 250 and the diastolic value could be any even number from 40 to 110, there had to be some type of error trapping to ensure the systolic reading wasn't actually lower than the diastolic reading. The pulse pressure is the difference between the systolic and diastolic numbers. Newsletter #114 contains an excellent tutorial on writing functions (Function Fundamentals by Alyce Watson). At that time, I thought creating functions was beyond my capabilities. I began paying attention to function snippets offered on the conforum. Soon, I was able to write the sysBP(value), dstBP(value) and pulsePress(sbp,dbp) functions to eliminate quite a bit of messy IF…THEN statements in the body of the main loop.
Creating functions is so very self - satisfying. But, creating a function is nothing compared to the pleased feeling experienced with the first successful 'call' command. Does everyone remember their first 'call' being answered, or is it just me? No matter. I was beginning to feel like a programmer.
I thought I was very pleased with the program. The program was functional and professional looking. Aha! I'm done now. Well, I thought I was done, until Gordon Sweet and Stefan Pendl put their heads together and offered text - to - speech for Liberty BASIC (Newsletters #117 and #118). Given the excellent instructions put forth by Stefan, I was able to extract the correct code and incorporate speech into the program. Great! A finished product!
Well, perhaps, not quite finished. As I was reviewing Jim Brossman's More than an Address Book, I became intrigued with the tooltips. Yes, tooltips would be a nice addition. Once again, I was back to the program, adding just one more detail. After all, don't ALL professional programs display helpful tooltips? Disabling a .bmp button to display a staticimage was a great tip gotten from the LB conforum (version 4.x required). The program was looking better and better.

So now the Blood Pressure Drill - and - Practice is finished . . . maybe. There is one major flaw. I'd like to somehow create a dial face that is more photo quality. And, I just saw a demo posted by Eldron Gill and Colin McMurchie showing printouts complete with print preview. Wouldn't the students like a printout of their successful readings? And then there's Brent Thorn's code (modified by Alyce Watson, Newsletter #98) showing how to change the icon at runtime. I think a nice 3-D heart might look very nice in the upper left corner. What about a beating 3-D heart? It seems to me I remember reading about something called AVI in Alyce's Mastering Liberty Basic 3 and the Liberty Basic 4 Companion. This program finished? Hardly. The program continues to evolve. And thanks to the LB community, I'm loving this evolution!
[Editor: Find Janet's Blood Presure Simulator included with the newsletter download - in the files archive. It is called Bpsim2_02.zip]